package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.config.annotation.DataScope;
import com.dragon.repository.entity.Admin;
import com.dragon.repository.entity.Department;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 部门表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-06-12
 */
@Mapper
public interface DepartmentMapper extends BaseMapper<Department> {

    @Select("WITH RECURSIVE os AS ( " +
            "    SELECT id,name,pid FROM dragon_department WHERE id = #{id} " +
            "    UNION ALL " +
            "    SELECT oo.id,oo.name,oo.pid FROM dragon_department oo INNER JOIN os oo1 ON oo.pid=oo1.id " +
            ") " +
            "SELECT " +
            "    o.id, " +
            "    o.name " +
            "FROM " +
            "    dragon_department o " +
            "        INNER JOIN os ON os.id = o.id")
    List<Department> selectDepartmentListByAdminId(Integer id);

    @Select("select B.* from dragon_admin_department A,dragon_department B " +
            "where A.department_id = B.id and A.admin_id = #{id} ")
    Department selectDepartmentInfoByAdminId(Integer id);

    /**
     * 根据id获取部门名称
     * @param departmentId
     * @return
     */
    @Select("SELECT a.name FROM dragon_department a WHERE a.id = #{department}")
    String selectDepartNameById(Integer departmentId);



}
